package cn.usian.service.impl;

import cn.usian.mapper.StudentMapper;
import cn.usian.pojo.Student;
import cn.usian.service.StudentService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
public class StudentServiceImpl implements StudentService {

    @Resource
    private StudentMapper studentMapper;

    @Override
    public Page<Student> findPage(Integer pageIndex, String name) {
        LambdaQueryWrapper<Student> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(name!=null,Student::getName,name);
        Page<Student> page = new Page<>(pageIndex, 2);
        Page<Student> studentPage = studentMapper.selectPage(page, queryWrapper);

        return studentPage;
    }

    @Override
    public void add(Student student) {
        studentMapper.insert(student);
    }

    @Override
    public void del(Long id) {
        studentMapper.deleteById(id);
    }
}
